package com.jjc.android.entity;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class VarPair<A,B> {

    private A first;
    private B second;

    public VarPair(A first, B second) {
        this.first = first;
        this.second = second;
    }

    public VarPair() {
    }


    private Function1<VarPair<A,B>, Unit> listener;

    public void registerListener(Function1<VarPair<A,B>, Unit> listener){
        this.listener = listener;
    }

    public VarPair(Function1<VarPair<A, B>, Unit> listener) {
        this.listener = listener;
    }

    public void putData(A first, B second){
        this.first = first;
        this.second = second;
        notifyListener();
    }

    private void notifyListener(){
        if(listener!=null){
            listener.invoke(this);
        }
    }

    public A getFirst() {
        return first;
    }

    public void setFirst(A first) {
        this.first = first;
        notifyListener();
    }

    public B getSecond() {
        return second;
    }

    public void setSecond(B second) {
        this.second = second;
        notifyListener();
    }
}
